#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
# 激活激光头
'''
DO NOT WATCH THE LASER DERECTELY IN THE EYE!
使用电压DC5V，静态电流小于2mA，电平输出低于0V，感应角度不大于15度，探测距离2cm-450cm，高精度可达3mm
'''
LedPin = 24  # pin11


def setup():
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(LedPin, GPIO.OUT)  # Set LedPin's mode is output
    GPIO.output(LedPin, GPIO.LOW)  # Set LedPin LOW(0V) to off led


def loop():
    while True:
        print('...Laser off')
        GPIO.output(LedPin, GPIO.LOW)  # led off
        time.sleep(0.5)
        print('Laser on...')
        GPIO.output(LedPin, GPIO.HIGH)  # led on
        time.sleep(0.5)


def destroy():
    GPIO.output(LedPin, GPIO.LOW)
    GPIO.cleanup()  # Release resource


if __name__ == '__main__':  # Program start from here
    setup()
    try:
        loop()
    except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
        destroy()
